package com.xiaoshuidi.cloud.module.report.controller.bigdata;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.report.controller.bigdata.vo.*;
import com.xiaoshuidi.cloud.module.report.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.report.service.bigdata.OverViewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;


/**
 * 整体运营概况
 */
@Slf4j
@RestController
@RequestMapping(ApiConstants.PREFIX + "/overView")
@PermitAll
public class OverViewController {

    @Resource
    private OverViewService overViewService;

    /**
     * 运营概况总览
     *
     * @return {@link CommonResult}<{@link OverViewHouseDataVO}>
     */
    @GetMapping("/getOverViewHouseData")
    public CommonResult<OverViewHouseDataVO> getOverViewHouseData() {
        return success(overViewService.getOverViewHouseData());
    }

    /**
     * 运营概况区域地图门店房源统计
     *
     * @return {@link CommonResult}<{@link Map}<{@link String}, {@link List}<{@link HouseMapStatisticsVO}>>>
     */
    @GetMapping("/houseMapStatistics")
    public CommonResult<Map<String, List<HouseMapStatisticsVO>>> houseMapStatistics() {
        return success(overViewService.houseMapStatistics());
    }

    /**
     * 租客占比
     *
     * @return {@link CommonResult}<{@link List}<{@link PieChartResultVO}>>
     */
    @GetMapping("/groupCustomerTypeByCount")
    public CommonResult<List<PieChartResultVO>> groupCustomerTypeByCount() {
        return success(overViewService.groupCustomerTypeByCount());
    }

    /**
     * 个人租客年龄分布
     *
     * @return {@link CommonResult}<{@link List}<{@link PieChartResultVO}>>
     */
    @GetMapping("/personalAgeInterval")
    public CommonResult<List<PieChartResultVO>> personalAgeInterval() {
        return success(overViewService.personalCustomerAgeIntervalCount());
    }

    /**
     * 营业占比
     *
     * @return {@link CommonResult}<{@link List}<{@link PieChartResultVO}>>
     */
    @GetMapping("/businessStatisticsCount")
    public CommonResult<List<PieChartResultVO>> businessStatisticsCount() {
        return success(overViewService.businessStatisticsCount());
    }

    /**
     * 年平均租金top15
     *
     * @return {@link CommonResult}<{@link List}<{@link ApartmentAvgMonthRentVO}>>
     */
    @GetMapping("/apartmentAvgMonthRentStatistics")
    public CommonResult<List<ApartmentAvgMonthRentVO>> apartmentAvgMonthRentStatistics() {
        Page page = new Page(1L, 15L);
        return success(overViewService.apartmentAvgMonthRentStatistics(page));
    }


    /**
     * 营收top10门店
     *
     * @return {@link CommonResult}<{@link List}<{@link ApartmentRevenueVO}>>
     */
    @GetMapping("/apartmentRevenueByYear")
    public CommonResult<List<ApartmentRevenueVO>> apartmentRevenueByYear() {
        Page page = new Page(1L, 10L);
        return success(overViewService.apartmentRevenueByYear(page, DateUtil.thisYear()));
    }

    /**
     * 获取年份下门店入住人数 包括同住人top10
     *
     * @return {@link CommonResult}<{@link List}<{@link StoreCheckInVO}>>
     */
    @GetMapping("/storeCheckInAnalysisByYear")
    public CommonResult<List<StoreCheckInVO>> storeCheckInAnalysisByYear() {
        Page page = new Page(1L, 10L);
        return success(overViewService.storeCheckInAnalysisByYear(page, DateUtil.thisYear()));
    }

    /**
     * 获取年份下门店月平均入住人数 包括同住人top15
     *
     * @return {@link CommonResult}<{@link List}<{@link StoreCheckInVO}>>
     */
    @GetMapping("/storeCheckInAvgAnalysisTopByYear")
    public CommonResult<List<StoreCheckInVO>> storeCheckInAvgAnalysisTopByYear() {
        Page page = new Page(1L, 15L);
        return success(overViewService.storeCheckInAvgAnalysisByYear(page, DateUtil.thisYear()));
    }




}
